Lesson 1 - Advanced exercise

Translate the following code examples.


# advanced example 1
def ugSentance(text):
	words = text.split(text)
	for singleWord in words:
		print "ug" , singleWord

ugSentance("This is a test sentance")

Toggle answer

# advanced example 2
import random
import string
import time

def mkpass(size=16):
    chars = []
    chars.extend([i for i in string.ascii_letters])
    chars.extend([i for i in string.digits])
    chars.extend([i for i in '\'"!@#$%&*()-_=+[{}]~^,<.>;:/?'])
    
    passwd = ''
    
    for i in range(size):
        passwd += chars[random.randint(0,  len(chars) - 1)]
        random.seed = int(time.time())
        random.shuffle(chars)
    return passwd

print mkpass(8)

Toggle answer